package design.simdi.code.final_paper.site.panels.proiecte.keywords;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.hibernate.criterion.Restrictions;

import design.simdi.code.final_paper.core.daos.KeywordDao;
import design.simdi.code.final_paper.core.entities.Keyword;
import design.simdi.code.final_paper.site.application.WicketApplication;
import design.simdi.code.final_paper.site.panels.PagePanel;
import design.simdi.code.final_paper.utils.ActionToolbar;
import design.simdi.code.final_paper.utils.MyDataTable;

/**
 * 
 * @author Marius Dumitriu - (Jun 21, 2010 - 3:24:40 PM)
 * 
 */
public class CuvinteCheieTabPanel extends PagePanel {
	private static final long serialVersionUID = 1L;
	@SpringBean
	private KeywordDao keywordDao;

	public CuvinteCheieTabPanel(String id) {
		super(id);
		InjectorHolder.getInjector().inject(this);
		((WicketApplication) getApplication()).setShowErrors(true);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void panelInit() {
		List<IColumn<Keyword>> columns = new ArrayList<IColumn<Keyword>>();

		columns.add(new PropertyColumn(new ResourceModel("name"), "name", "name"));
		columns.add(new PropertyColumn(new ResourceModel("description"), "description"));

		SortableKeywordDataProvider sortableKeywordDataProvider = new SortableKeywordDataProvider();
		sortableKeywordDataProvider.getCriterii().add(Restrictions.eq("person.id", getCurrentPerson().getId()));

		add(new MyDataTable<Keyword>("table", columns, sortableKeywordDataProvider, getRowsPerPage()) {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public ActionToolbar getActionToolbar() {
				return new KeywordActionToolbar(this);
			}
		});
	}

	public void setKeywordDao(KeywordDao keywordDao) {
		this.keywordDao = keywordDao;
	}

	public KeywordDao getKeywordDao() {
		return keywordDao;
	}
}
